<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
     pre-  1 - 2  -3-4
         cur  next
      2   -  1-3-4
     next   cur
      */
      var swapPairs = function (head) {
        let dummy = new ListNode(0, head)
        let pre = dummy
        let cur = head
        //每次交换两个即跳两步
        while (cur && cur.next) {
          let next = cur.next
          let next2 = cur.next.next
          cur.next = next2
          next.next = cur
          pre.next = next
          pre = cur
          cur = next2
        }
        return dummy.next
      }
    </script>
  </body>
</html>
